home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-05 / drivers2.zip / PIXEL.ASM < prev    next >
Assembly Source File  |  1992-01-17  |  6KB  |  339 lines

  1. ;put into the public domain by Russell Nelson, nelson@crynwr.com
  2. ; code to do graphics at 320x200x256 on both EGAs and VGAs.
  3.  
  4. address_list    label    word
  5. ;can't change es, di, dx, or ah.
  6. ;al and bx will get trashed, but they need not be preserved.
  7. open_vid    dw    ?
  8. move_right    dw    ?
  9. move_left    dw    ?
  10. move_up        dw    ?
  11. move_down    dw    ?
  12. set_bit        dw    ?
  13. close_vid    dw    ?
  14. uninit_vid    dw    ?
  15. address_end    label    word
  16.  
  17. ega_adrs    dw    init_vid_ega, open_vid_ega, move_right_ega, move_left_ega
  18.         dw    move_up_ega, move_down_ega, set_bit_ega, close_vid_ega
  19.         dw    uninit_vid_ega
  20.  
  21. vga_adrs    dw    init_vid_vga, open_vid_vga, move_right_vga, move_left_vga
  22.         dw    move_up_vga, move_down_vga, set_bit_vga, close_vid_vga
  23.         dw    uninit_vid_vga
  24.  
  25.  
  26. init_vid:
  27. ;test for VGA.
  28.     mov    ax,1a00h
  29.     int    10h
  30.     cmp    al,1ah
  31.     mov    si,offset vga_adrs
  32.   ifndef FORCE_EGA
  33.     je    have_vga
  34.   endif
  35.     mov    si,offset ega_adrs
  36. have_vga:
  37.     lodsw                ;get the init_vid_* routine.
  38.     push    ds
  39.     pop    es
  40.     mov    di,offset address_list
  41.     mov    cx,(offset address_end - offset address_list) / 2
  42.     rep    movsw
  43.     jmp    ax            ;jump to the proper init_vid routine.
  44.  
  45.  
  46. init_vid_vga:
  47.     mov    ax,13h            ;put the screen into vga mode.
  48.     int    10h
  49.  
  50.     call    pal_save        ;save the palette
  51.     call    pal_setgrey        ;set to a gray palette.
  52.  
  53.     ret
  54.  
  55. uninit_vid_vga:
  56.     call    pal_restore
  57.  
  58.     mov    ax,3h            ;put the screen into text mode.
  59.     int    10h
  60.  
  61.     ret
  62.  
  63.  
  64. init_vid_ega:
  65.     mov    ax,10h            ;put the screen into ega mode.
  66.     int    10h
  67.  
  68.     mov    ax,1000h        ;change the palette entry for 7
  69.     mov    bx,77Q*256 + 7        ;  to 77 octal.
  70.     int    10h
  71.  
  72.     mov    ax,1000h
  73.     mov    bx,007Q*256 + 08h
  74.     int    10h
  75.  
  76.     mov    ax,1000h
  77.     mov    bx,010Q*256 + 09h
  78.     int    10h
  79.  
  80.     mov    ax,1000h
  81.     mov    bx,020Q*256 + 0ah
  82.     int    10h
  83.  
  84.     mov    ax,1000h
  85.     mov    bx,030Q*256 + 0bh
  86.     int    10h
  87.  
  88.     mov    ax,1000h
  89.     mov    bx,040Q*256 + 0ch
  90.     int    10h
  91.  
  92.     mov    ax,1000h
  93.     mov    bx,050Q*256 + 0dh
  94.     int    10h
  95.  
  96.     mov    ax,1000h
  97.     mov    bx,060Q*256 + 0eh
  98.     int    10h
  99.  
  100.     mov    ax,1000h
  101.     mov    bx,070Q*256 + 0fh
  102.     int    10h
  103.  
  104.     ret
  105.  
  106.  
  107. uninit_vid_ega:
  108.     mov    ax,3h            ;put the screen into text mode.
  109.     int    10h
  110.  
  111.     ret
  112.  
  113.  
  114. pal_save:
  115. ;Save existing palette
  116.     mov    ax,1017h        ;get all palette registers.
  117.     mov    bx,0            ;first palette register.
  118.     mov    cx,256            ;read all palette registers.
  119.     push    ds
  120.     pop    es
  121.     mov    dx,offset save_dacs
  122.     int    10h
  123.  
  124.     ret
  125.  
  126.  
  127. pal_setgrey:
  128.     mov    di,offset gray_dacs
  129.     mov    al,0
  130. pal_setgrey_1:
  131.     mov    cx,3 * 256 / 64        ;3 colors, 256 grays, 64 slots.
  132.     rep    stosb
  133.  
  134.     inc    al
  135.     cmp    al,64
  136.     jb    pal_setgrey_1
  137.  
  138.     mov    dx,offset gray_dacs
  139.     jmp    short pal_set
  140.  
  141. pal_restore:
  142.     mov    dx,offset save_dacs
  143. pal_set:
  144.     mov    ax,1012h        ;set all palette registers.
  145.     mov    bx,0            ;first palette register.
  146.     mov    cx,256            ;read all palette registers.
  147.     push    ds
  148.     pop    es
  149.     int    10h
  150.  
  151.     ret
  152.  
  153.  
  154. open_vid_vga:
  155. ;enter with cx,dx = point on screen.
  156. ;exit with es:di,ah -> byte/bit on screen.
  157.     mov    ax,0a000h
  158.     mov    es,ax
  159.     mov    ax,320            ;width of screen.
  160.     mul    dx
  161.     add    ax,cx            ;add the offset in.
  162.     mov    di,ax            ;remember our pointer.
  163.     ret
  164.  
  165.  
  166. move_right_vga:
  167.     inc    di
  168.     ret
  169.  
  170. move_left_vga:
  171.     dec    di
  172.     ret
  173.  
  174. move_up_vga:
  175.     sub    di,320            ;width of screen.
  176.     ret
  177.  
  178. move_down_vga:
  179.     add    di,320            ;width of screen.
  180.     ret
  181.  
  182. set_bit_vga:
  183.     mov    es:[di],al
  184.     ret
  185.  
  186. close_vid_vga:
  187.     ret
  188.  
  189.  
  190. open_vid_ega:
  191. ;enter with cx,dx = point on screen.
  192. ;exit with es:di,ah -> byte/bit on screen.
  193.     mov    ax,0a000h
  194.     mov    es,ax
  195.     mov    ax,640/8*2        ;bytes per scan line * scan lines per pixel
  196.     mul    dx
  197.     mov    di,ax
  198.     mov    ax,cx            ;/8*2
  199.     shr    ax,1
  200.     shr    ax,1
  201.     add    di,ax
  202.  
  203.     mov    dx,03ceh        ;graphics controller
  204.     mov    ax,0205h        ;write mode 2.
  205.     out    dx,al
  206.     inc    dx
  207.     mov    al,ah
  208.     out    dx,al
  209.     dec    dx
  210.     mov    al,08h            ;select bitmap register.
  211.     out    dx,al
  212.     inc    dx
  213.  
  214.     shl    cx,1            ;compute the bit.
  215.     and    cl,7
  216.     mov    ah,80h
  217.     shr    ah,cl
  218.     ret
  219.  
  220.  
  221. move_right_ega:
  222.     shr    ah,1            ;move right by a bit.
  223.     ror    ah,1            ;move right by another bit,
  224.     adc    di,0            ;  and handle byte increment.
  225.     ret
  226.  
  227.  
  228. move_left_ega:
  229.     rol    ah,1            ;move left by a bit,
  230.     adc    di,0            ;  and handle byte increment.
  231.     shl    ah,1            ;move left by another bit.
  232.     ret
  233.  
  234.  
  235. move_up_ega:
  236.     sub    di,80*2            ;width of screen.
  237.     ret
  238.  
  239.  
  240. move_down_ega:
  241.     add    di,80*2            ;width of screen.
  242.     ret
  243.  
  244.  
  245. set_bit_ega:
  246.     mov    bl,al
  247.     xor    bh,bh
  248.  
  249.     mov    al,ah
  250.     out    dx,al
  251.     mov    al,ulpal[bx]
  252.     xchg    es:[di],al        ;store the palette value.
  253.     mov    al,llpal[bx]
  254.     xchg    es:[di+80],al        ;store the palette value.
  255.  
  256.     shr    ah,1            ;move right by a bit.
  257.  
  258.     mov    al,ah
  259.     out    dx,al
  260.     mov    al,urpal[bx]
  261.     xchg    es:[di],al        ;store the palette value.
  262.     mov    al,lrpal[bx]
  263.     xchg    es:[di+80],al        ;store the palette value.
  264.  
  265.     shl    ah,1            ;restore the bit.
  266.  
  267.     ret
  268.  
  269.  
  270. close_vid_ega:
  271.     mov    al,0ffh            ;mask = all ones.
  272.     out    dx,al
  273.     dec    dx
  274.     mov    ax,0005h        ;write mode 0
  275.     out    dx,al
  276.     inc    dx
  277.     mov    al,ah
  278.     out    dx,al
  279.  
  280.     ret
  281.  
  282. ulpal    db    20 dup(00h)
  283.     db    20 dup(09h)
  284.     db    20 dup(0bh)
  285.     db    20 dup(0fh)
  286.     db    20 dup(0fh)
  287.     db    20 dup(0fh)
  288.     db    20 dup(0fh)
  289.     db    20 dup(08h)
  290.     db    20 dup(08h)
  291.     db    20 dup(07h)
  292.     db    20 dup(07h)
  293.     db    20 dup(07h)
  294.     db    20 dup(07h)
  295. urpal    db    20 dup(00h)
  296.     db    20 dup(00h)
  297.     db    20 dup(0ch)
  298.     db    20 dup(0eh)
  299.     db    20 dup(0fh)
  300.     db    20 dup(08h)
  301.     db    20 dup(08h)
  302.     db    20 dup(08h)
  303.     db    20 dup(08h)
  304.     db    20 dup(08h)
  305.     db    20 dup(08h)
  306.     db    20 dup(08h)
  307.     db    20 dup(07h)
  308. llpal    db    20 dup(00h)
  309.     db    20 dup(0ch)
  310.     db    20 dup(0ch)
  311.     db    20 dup(0dh)
  312.     db    20 dup(0fh)
  313.     db    20 dup(0fh)
  314.     db    20 dup(08h)
  315.     db    20 dup(08h)
  316.     db    20 dup(08h)
  317.     db    20 dup(08h)
  318.     db    20 dup(08h)
  319.     db    20 dup(07h)
  320.     db    20 dup(07h)
  321. lrpal    db    20 dup(00h)
  322.     db    20 dup(0ah)
  323.     db    20 dup(0bh)
  324.     db    20 dup(0bh)
  325.     db    20 dup(0fh)
  326.     db    20 dup(0fh)
  327.     db    20 dup(0fh)
  328.     db    20 dup(0fh)
  329.     db    20 dup(08h)
  330.     db    20 dup(08h)
  331.     db    20 dup(07h)
  332.     db    20 dup(07h)
  333.     db    20 dup(07h)
  334.  
  335. save_dacs    db    256 * 3 dup(?)
  336. gray_dacs    db    256 * 3 dup(?)
  337.  
  338.  
  339.